//  表格区域  组件
<template>
  <el-table :data="directoryList"
            style="width: 100%">
    <el-table-column type="index"
                     label="序号">
    </el-table-column>
    <el-table-column prop="subjectName"
                     label="所属学科">
    </el-table-column>
    <el-table-column prop="directoryName"
                     label="目录名称">
    </el-table-column>
    <el-table-column prop="username"
                     label="创建着">
    </el-table-column>
    <el-table-column prop="addDate"
                     label="创建日期">
      <template slot-scope="scope">
        {{ scope.row.addDate | parseTimeByString }}
      </template>
    </el-table-column>
    <el-table-column prop="totals"
                     label="面试题数量">
    </el-table-column>
    <el-table-column prop="state"
                     label="状态">
      <template slot-scope="scope">
        {{ scope.row.state ? '已启用' : '已禁用' }}
      </template>
    </el-table-column>
    <el-table-column prop="address"
                     label="操作">
      <template slot-scope="scope">
        <el-button type="text"
                   @click="editState(scope.row)">{{ scope.row.state === 1 ? '禁用' : '启用' }}</el-button>
        <el-button type="text"
                   :disabled="scope.row.state === 1"
                   @click='$emit("openEdit",scope.row)'>修改</el-button>
        <el-button type="text"
                   :disabled="scope.row.state === 1"
                   @click="deleteDir(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>



<script>
import { changeState } from '../../api/hmmm/directorys'
export default {
  name: 'directoryTable',
  props: {
    directoryList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      idx: {}
    }
  },
  methods: {
    //切换状态
    async editState(row) {
      try {
        await changeState({
          id: row.id,
          state: row.state === 1 ? 0 : 1
        })
        this.$message.success('操作成功')
        row.state = row.state === 1 ? 0 : 1
      } catch (error) {
        this.$message.error('请求错误!')
      }
    },

    deleteDir(val) {
      this.idx = val
      this.$emit('updateIdx', val)
    }
  }
}
</script>


<style scoped lang='scss'>
</style>
